class_name Bag
extends Resource

signal updated

@export var cells:Array[BagCell]

func add(item:BagItem):
    # 物品进入背包空格
    for cell in cells:
        if cell.item==item:
            if cell.num>=item.maxNumber:
                addToBlank(item)
                return
            cell.num+=1
            updated.emit()
            return
    addToBlank(item)
    
# 新增到空包
func addToBlank(item):
    for i in range(cells.size()):
        if !cells[i].item:
            cells[i].item=item
            cells[i].num=1
            updated.emit()
            return
    